﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.EntityModel;

namespace DataAccess
{
    public static class EmployeeDataAccess
    {
        public static Employee InsertEmployee(Employee newEmployee)
        {
            BrigadaEntities context = new BrigadaEntities();
            context.AddToEmployee(newEmployee);
            context.SaveChanges();
            return newEmployee;
        }

        public static bool EmployeeAlreadyExists(long ciEmployee)
        {
            BrigadaEntities context = new BrigadaEntities();
            var employee = (from e in context.Employee
                          where e.CI == ciEmployee
                          select e).SingleOrDefault();
            return (employee != null);
        }

        public static Employee GetEmployeeByCi(long ciEmployee)
        {
            BrigadaEntities context = new BrigadaEntities();
            var employee = (from e in context.Employee
                          where e.CI == ciEmployee
                          select e).SingleOrDefault();
            return employee;
        }

        public static Employee UpdateEmployee(long ciEmployee, Employee newInfo)
        {
            BrigadaEntities context = new BrigadaEntities();
            var employee = (from e in context.Employee
                          where e.CI == ciEmployee
                          select e).SingleOrDefault();
            employee = newInfo;
            context.SaveChanges();
            return employee;
        }

        public static List<Employee> GetAllEmployees()
        {
            BrigadaEntities context = new BrigadaEntities();
            var query = from elem in
                            context.Employee
                        select elem;
            return query.ToList();
        }
    }
}
